package com.taotao.controller;

import com.taotao.common.pojo.EasyUIDataGridResult;
import com.taotao.common.pojo.TaotaoResult;
import com.taotao.pojo.TbItem;
import com.taotao.service.ItemService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class ItemController {
	@Autowired
	private ItemService itemService;

	@ResponseBody
	@RequestMapping("/item/{itemId}")
	public TbItem getItemById(@PathVariable("itemId") Long itemId) {
		TbItem tbItem = itemService.getItemById(itemId);
		return tbItem;
	}

	@RequestMapping("/item/list")
	@ResponseBody
	public EasyUIDataGridResult getItemList(Integer page, Integer rows) {
		EasyUIDataGridResult result = itemService.getItemList(page, rows);
		return result;
	}

	@RequestMapping(value ="/item/save", method =RequestMethod.POST)
	@ResponseBody
	public TaotaoResult createItem(TbItem item, String desc, String itemParams) {
		TaotaoResult result = itemService.createItem(item, desc, itemParams);
		return result;
	}

	@RequestMapping(value ="/rest/item/update", method =RequestMethod.POST)
	@ResponseBody
	public TaotaoResult updateItem(TbItem item, String desc, String itemParams) {
		TaotaoResult result = itemService.itemUpdate(item, desc, itemParams);
		return result;
	}

	@RequestMapping("/rest/item/delete")
	@ResponseBody
	public TaotaoResult deleteItem(long[] ids) {
		TaotaoResult result = itemService.deleteItem(ids);
		return result;
	}

	@RequestMapping("/rest/item/instock")
	@ResponseBody
	public TaotaoResult itemsInstock(long[] ids) {
		TaotaoResult result = itemService.itemsInstock(ids);
		return result;
	}

	@RequestMapping("/rest/item/reshelf")
	@ResponseBody
	public TaotaoResult itemsReshelf(long[] ids) {
		TaotaoResult result = itemService.itemsReshelf(ids);
		return result;
	}
}
